<template>
<div id="app">
    <nav class="navbar">
      <!-- 导航栏左侧标题，去掉“标题”二字 -->
      <div class="navbar-left">
        <span>影评系统</span>
      </div>
      <!-- 导航栏中间导航项 -->
      <div class="navbar-middle">
        <router-link class="nav-link" to="/" exact-active-class="active-link">首页</router-link>
       <router-link 
  class="nav-link" 
  to="/category"
  :class="{ 'active-link': $route.path.startsWith('/category') }"
>
  分类
</router-link>
        <!-- 添加搜索框 -->
        <div class="search-box" :class="{ 'active-search': isSearchPage }">
          <img
            src="./assets/search.svg"
            style="height: 36px; width: 36px; margin-right: 15px;"
            :class="{ 'active-icon': isSearchPage }"
          />
          <input
            type="text"
            placeholder="搜索电影..."
            class="search-input"
            v-model="searchQuery"
            @keyup.enter="performSearch"
          />
          <button class="search-button" @click="performSearch">搜索</button>
        </div>
      </div>
      <!-- 导航栏右侧登录按钮 -->
      <div class="navbar-right">
        <button>登录</button>
      </div>
    </nav>
    <!-- 页面内容区域 -->
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      searchQuery: '',
      isSearchPage: false
    };
  },
  watch: {
    $route(to) {
      this.isSearchPage = to.name === 'FilmSearch';
    }
  },
  methods: {
    performSearch() {
      if (this.searchQuery.trim()) {
        this.$router.push({
          name: 'FilmSearch',
          query: { q: this.searchQuery.trim() }
        });
      }
    }
  },
  created() {
    this.isSearchPage = this.$route.name === 'FilmSearch';
  }
};
</script>

<style>
/* #app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
} */
 html, body {
  margin: 0;
  padding: 0;
}
 /* 为整个页面添加灰黑背景色 */
#app {
  background-color: #333333;
  min-height: 100vh;
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* 略微放大导航栏 */
  padding: 20px 30px;
  background-color: #222222;
  /* 添加阴影效果 */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.navbar-left,
.navbar-middle,
.navbar-right {
  display: flex;
  align-items: center;
}

.navbar-left span {
  color: white;
  font-size: 24px;
  font-weight: bold;
}

.navbar-middle .nav-link {
  /* 增大首页与分类的间隙 */
  margin: 0 25px;
  text-decoration: none;
  color: #ffffffee;
  font-size: 18px;
  /* 添加过渡效果 */
  transition: color 0.3s ease;
}

/* 鼠标悬停时改变颜色 */
.nav-link:hover {
  color: #007bff;
}

.nav-link {
  position: relative;
  /* 使边框定位相对 */
  padding: 10px;
  /* 增加内边距 */
}

.active-link {
  border-bottom: 2px solid white;
  /* 添加白色下边框 */
}

.navbar-right button {
  padding: 10px 25px;
  border: none;
  border-radius: 5px;
  background-color: #007bff;
  color: white;
  cursor: pointer;
  font-size: 18px;
  /* 添加过渡效果 */
  transition: background-color 0.3s ease;
}

/* 鼠标悬停时改变按钮背景色 */
.navbar-right button:hover {
  background-color: #0056b3;
}

/* 修改搜索框样式 */
.search-box {
  display: flex;
  align-items: center;
  margin-left: 800px;
}

.search-input {
  padding: 8px;
  border: 2px solid #ffffffee;
  /* 添加常驻边框，颜色可以根据需要调整 */
  border-radius: 5px 0 0 5px;
  font-size: 16px;
  background-color: #444444;
  /* 修改背景颜色为灰色 */
  color: white;
  /* 设置文字颜色为白色，提高可读性 */
  transition: background-color 0.3s ease;
  /* 添加过渡效果 */
}

.search-input:hover {
  /* 鼠标悬停时改变背景颜色 */
  background-color: #555555;
}

.search-input:focus {
  /* 去掉默认的聚焦轮廓 */
  outline: none;
}

.search-button {
  padding: 8px 15px;
  border: none;
  border-radius: 0 5px 5px 0;
  background-color: #444444;
  /* 修改按钮背景颜色为灰色 */
  color: white;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s ease;
  /* 添加过渡效果 */
}

.search-button:hover {
  background-color: #555555;
  /* 鼠标悬停时改变按钮背景颜色 */
}

/* 新增搜索页样式 */
.search-box.active-search {
  position: relative;
}

.search-box.active-search::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: white;
}

.active-icon {
  filter: brightness(0) invert(1); /* 可以根据需要调整图标样式 */
}
</style>
